/**
 * @param {string} s
 * @return {boolean}
 */

var isValid = function(s) {
    let stack=[];
    let currentLeft = [];
    for(let i=0;i<s.length;i++){
        
        if(s[i]=='(' || s[i]=='{'|| s[i] == '['){
            currentLeft.push(s[i])
            stack.push(s[i]);
            
        }else{
            let currentRight = s[i];
            if(currentLeft.length==0) return;
            if(currentLeft[currentLeft.length-1] == '(' && currentRight == ')' ||
                currentLeft[currentLeft.length-1] == '{' && currentRight == '}' ||
                currentLeft[currentLeft.length-1] == '[' && currentRight == ']' 
            ){ stack.pop();
                currentLeft.pop();
            }
            else{
                return false
            }

        }
    }
    return stack.length == 0
};